package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.Pagingable;
import com.yxy.base.RestResponse;
import com.yxy.dto.TableHouseDto;
import com.yxy.dto.TableSetMealDto;
import com.yxy.service.TableSetMealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author huangxinrong
 *  套餐管理
 */
@RestController
@Slf4j
@RequestMapping("/tableSetMeal")//必须要加
public class TableSetMealController {

  @Autowired
  private TableSetMealService tableSetMealService;

  // 获取商品列表
  @Pagingable//添加分页
  @PostMapping("/list")
  public RestResponse getList(@RequestBody TableSetMealDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableSetMealService.getlist(pojo));
    return restResponse;
  }

  //修改商品类型信息
  @PostMapping("/update")
  public RestResponse update(@RequestBody @Valid  TableSetMealDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableSetMealService.modify(pojo));
    return restResponse;
  }

  //新增商品类型信息
  @PostMapping("/create")
  public RestResponse create(@RequestBody @Valid  TableSetMealDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableSetMealService.save(pojo));
    return restResponse;
  }

  //根据id删除商品类型信息
  @PostMapping("/delete")
  public RestResponse delete(@RequestBody @Valid  TableSetMealDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableSetMealService.delete(pojo.getId().toString()));
    return restResponse;
  }
}
